let loginModule = {
    namespaced:true,
    state:{
        token:'',
        userInfo:'',
        addressList:[]
    },
    getters:{
        getToken(_state){
            return _state.token
        },
        getUserInfo(_state){
            return _state.userInfo
        },
        getAddressList(_state){
            return _state.addressList
        }
    },
    mutations:{
        changeToken(_state,value){
            _state.token = value
        },
        changeUserInfo(_state,value){
            _state.userInfo = value
        },

        //添加地址
        addAddressList(_state,val){
            _state.addressList.push(val)
        },

        //删除地址
        deleteAddress(_state,val){
            _state.addressList = _state.addressList.filter(item => item.id !== val.id)

        },
        //清空地址
        clearAddr(_state){
            _state.addressList = []
        },

        accessAddressList(_state,val){
            _state.addressList = val
        },

        //改变地址选择状态
        changeCheck(_state,val){
            _state.addressList[val].check = !_state.addressList[val].check
        },

        //全部返回false
        allFalse(_state){
            _state.addressList.map(item => item.check = false)
        },

        //修改地址
        editAddress(_state,val){
            let index = _state.addressList.findIndex(item => item.id === val.id)
            _state.addressList.splice(index,1,val)
        }
    }
}

export default loginModule